package com.huabo.contract.mysql.mapper;

import com.hbfk.util.PageInfo;
import com.huabo.contract.mysql.entity.TblControlmatrixMySql;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author huabo
 * @since 2022-03-14
 */
public interface TblCounterpartBankinfoMySqlMapper extends BaseMapper<TblControlmatrixMySql> {

    @SelectProvider(type=TblCounterpartBankinfoMySqlMapperSqlConfig.class,method="findListByPageInfo")
    List<TblControlmatrixMySql> findListByPageInfo(PageInfo<TblControlmatrixMySql> pageInfo, TblControlmatrixMySql bank);

    @SelectProvider(type=TblCounterpartBankinfoMySqlMapperSqlConfig.class,method="selectCountByPageInfoCount")
    Integer selectCountByPageInfoCount(TblControlmatrixMySql bank);

    @InsertProvider(type=TblCounterpartBankinfoMySqlMapperSqlConfig.class,method="saveBank")
    void saveBank(TblControlmatrixMySql bank);

    @SelectProvider(type=TblCounterpartBankinfoMySqlMapperSqlConfig.class,method="findAllListByBankInfo")
    List<TblControlmatrixMySql> findAllListByBankInfo(PageInfo<TblControlmatrixMySql> pageInfo);
    @SelectProvider(type=TblCounterpartBankinfoMySqlMapperSqlConfig.class,method="findCountListByBankInfo")
    Integer findCountListByBankInfo(PageInfo<TblControlmatrixMySql> pageInfo);

    @UpdateProvider(type=TblCounterpartBankinfoMySqlMapperSqlConfig.class,method="updateByBankId")
    void updateByBankId(TblControlmatrixMySql bank);

    @Delete("DELETE FROM TBL_COUNTERPART_BANKINFO WHERE BANKID = #{bankId}")
    void removeBank(String bankId);

    @Update("UPDATE TBL_COUNTERPART_BANKINFO SET BANKSTATUS = #{bankstatus} WHERE BANKID = #{bankId}")
    void modifyBankStatus(String bankId, Integer bankstatus);

    @Select("SELECT * FROM TBL_COUNTERPART_BANKINFO WHERE BUDGETID = #{budgetId}")
    List<TblControlmatrixMySql> selectBankInfoByBugetId(Integer budgetId);

    @Delete("DELETE FROM TBL_COUNTERPART_BANKINFO WHERE BUDGETID = #{newBudgetId}")
    void deleteByBankInfo(Integer newBudgetId);

    @Select("SELECT SUM(PCOUNT) FROM ( SELECT COUNT(0) PCOUNT FROM TBL_CONTRACT_PAYMENT WHERE COUNTERBANK = #{bankId} UNION SELECT COUNT(0) PCOUNT FROM TBL_CONTRACT_COLLECTION WHERE COUNTERBANK = #{bankId} )")
    Integer selectCountByUser(String bankId);
}
